package tsinghua.smxq.mc;


import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Window; 
import android.widget.CompoundButton; 
import android.widget.RadioButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.TabHost; 
 
public class FoodPriceActivity extends TabActivity implements OnCheckedChangeListener{ 
     
    private TabHost mTabHost; 
    private Intent HistoryIntent; 
    private Intent RequestIntent; 
    private Intent SubmitIntent;     
    //用户ID
    public int userID = 0;
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
     //   requestWindowFeature(Window.FEATURE_NO_TITLE); 
        setContentView(R.layout.maintabs); 
                
        this.RequestIntent = new Intent(this,FoodPriceRequestActivity.class);
        this.RequestIntent.putExtra("userID", userID);
        this.SubmitIntent = new Intent(this,FoodPriceSubmitActivity.class);      
        this.SubmitIntent.putExtra("userID", userID); 
        this.HistoryIntent = new Intent(this,HistoryChartActivity.class); 
        this.HistoryIntent.putExtra("userID", userID);
        
        ((RadioButton) findViewById(R.id.radio_button1)) 
        .setOnCheckedChangeListener(this); 
        ((RadioButton) findViewById(R.id.radio_button2)) 
        .setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button0)) 
        .setOnCheckedChangeListener(this);
        setupIntent(); 
    } 
 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        if(isChecked){ 
            switch (buttonView.getId()) {            
            case R.id.radio_button1: 
                this.mTabHost.setCurrentTabByTag("REQUEST_TAB"); 
                break; 
            case R.id.radio_button2: 
                this.mTabHost.setCurrentTabByTag("SUBMIT_TAB"); 
                break;          
            case R.id.radio_button0: 
                this.mTabHost.setCurrentTabByTag("HISTORY_TAB"); 
                break; 
            } 
        } 
         
    } 
     
    private void setupIntent() { 
        this.mTabHost = getTabHost(); 
        TabHost localTabHost = this.mTabHost;       
 
        localTabHost.addTab(buildTabSpec("REQUEST_TAB", R.string.main_request, 
                R.drawable.request_btn, this.RequestIntent)); 
 
        localTabHost.addTab(buildTabSpec("SUBMIT_TAB", 
                R.string.main_submit, R.drawable.submit_btn, 
                this.SubmitIntent));
        
        localTabHost.addTab(buildTabSpec("HISTORY_TAB", R.string.main_history, 
                R.drawable.history_btn, this.HistoryIntent)); 
    } 
     
    private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon, 
            final Intent content) { 
        return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel), 
                getResources().getDrawable(resIcon)).setContent(content); 
    } 
} 
